﻿using UnityEngine;
using System.Collections;

public class BarrierObjectController : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnPress(bool pressed)
	{
		collider.enabled = !pressed;
		
		if( !pressed)
		{
			Collider col = UICamera.lastHit.collider;
			if( col == null || col.GetComponent<ViewportHolder>() == null)
			{
				transform.localPosition = Vector3.zero;
			}
				
		}
	}
	
	
	private UIButton button;
	private UILabel  label;
	
	void Awake()
	{
		button = GetComponentInChildren<UIButton>();
		label  = GetComponentInChildren<UILabel>();
	}
	
	public IEnumerator Cooldown(int cooldown)
	{
		button.isEnabled = false;
		button.UpdateColor(false, true);
		while(cooldown > 0)
		{
			label.text = Localization.instance.Get ("Wait") + " " + cooldown.ToString() + "s";
			cooldown -=1;
			yield return new WaitForSeconds(1);
		}
		CooldownFinished();
	}
	
	void CooldownFinished()
	{
		label.text = Localization.instance.Get("Barrier");
		
		button.isEnabled = true;
		button.UpdateColor(true, true);
		
		transform.localScale = Vector3.zero;
		TweenScale.Begin(gameObject, 0.3f, new Vector3(1,1,1));
		
		NotificationManager.instance.Show(NotificationManager.Type.BarrierAvailable, 1.5f);
	}
}
